
package com.daguchuangyi.erp_android.model.product;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.daguchuangyi.erp_android.manager.NetworkManager;
import com.daguchuangyi.erp_android.productlist.ProductSummaryManager;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class Product implements Parcelable, MultiItemEntity {

    @SerializedName("cassetteImage")
    @Expose
    private String cassetteImage;
    @SerializedName("exhibitionImage")
    @Expose
    private String exhibitionImage;
    @SerializedName("editedAt")
    @Expose
    private String editedAt;
    @SerializedName("reviewedAt")
    @Expose
    private String reviewedAt;
    @SerializedName("previousProduct")
    @Expose
    private Object previousProduct;
    @SerializedName("diff")
    @Expose
    private List<Object> diff = new ArrayList<Object>();
    @SerializedName("parameterDiff")
    @Expose
    private List<Object> parameterDiff = new ArrayList<Object>();
    @SerializedName("photosDiff")
    @Expose
    private List<Object> photosDiff = new ArrayList<Object>();
    @SerializedName("id")
    @Expose
    private int id;
    @SerializedName("PNO")
    @Expose
    private String pNO;
    @SerializedName("categoryId")
    @Expose
    private String categoryId;
    @SerializedName("newCategoryId")
    @Expose
    private Object newCategoryId;
    @SerializedName("operatorId")
    @Expose
    private int operatorId;
    @SerializedName("reviewStatus")
    @Expose
    private String reviewStatus;
    @SerializedName("rejectReason")
    @Expose
    private Object rejectReason;
    @SerializedName("uploadingImage")
    @Expose
    private boolean uploadingImage;
    @SerializedName("uploadFailed")
    @Expose
    private boolean uploadFailed;
    @SerializedName("imageId")
    @Expose
    private String imageId;
    @SerializedName("cad")
    @Expose
    private Object cad;
    @SerializedName("createdAt")
    @Expose
    private String createdAt;
    @SerializedName("updatedAt")
    @Expose
    private String updatedAt;
    @SerializedName("shelves")
    @Expose
    private List<Shelf> shelves = new ArrayList<>();
    @SerializedName("storage")
    @Expose
    private List<Storage> storage = new ArrayList<Storage>();
    @SerializedName("operator")
    @Expose
    private Operator operator;
    @SerializedName("parameters")
    @Expose
    private List<Parameter> parameters = new ArrayList<Parameter>();
    @SerializedName("photos")
    @Expose
    private List<Photo> photos = new ArrayList<>();
    public final static Creator<Product> CREATOR = new Creator<Product>() {


        @SuppressWarnings({
                "unchecked"
        })
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        public Product[] newArray(int size) {
            return (new Product[size]);
        }

    };

    protected Product(Parcel in) {
        this.cassetteImage = ((String) in.readValue((String.class.getClassLoader())));
        this.exhibitionImage = ((String) in.readValue((String.class.getClassLoader())));
        this.editedAt = ((String) in.readValue((String.class.getClassLoader())));
        this.reviewedAt = ((String) in.readValue((String.class.getClassLoader())));
        this.previousProduct = ((Object) in.readValue((Object.class.getClassLoader())));
        in.readList(this.diff, (Object.class.getClassLoader()));
        in.readList(this.parameterDiff, (Object.class.getClassLoader()));
        in.readList(this.photosDiff, (Object.class.getClassLoader()));
        this.id = ((int) in.readValue((int.class.getClassLoader())));
        this.pNO = ((String) in.readValue((String.class.getClassLoader())));
        this.categoryId = ((String) in.readValue((String.class.getClassLoader())));
        this.newCategoryId = ((Object) in.readValue((Object.class.getClassLoader())));
        this.operatorId = ((int) in.readValue((int.class.getClassLoader())));
        this.reviewStatus = ((String) in.readValue((String.class.getClassLoader())));
        this.rejectReason = ((Object) in.readValue((Object.class.getClassLoader())));
        this.uploadingImage = ((boolean) in.readValue((boolean.class.getClassLoader())));
        this.uploadFailed = ((boolean) in.readValue((boolean.class.getClassLoader())));
        this.imageId = ((String) in.readValue((String.class.getClassLoader())));
        this.cad = ((Object) in.readValue((Object.class.getClassLoader())));
        this.createdAt = ((String) in.readValue((String.class.getClassLoader())));
        this.updatedAt = ((String) in.readValue((String.class.getClassLoader())));
        in.readList(this.shelves, (Shelf.class.getClassLoader()));
        this.operator = ((Operator) in.readValue((Operator.class.getClassLoader())));
        in.readList(this.parameters, (Parameter.class.getClassLoader()));
        in.readList(this.photos, (Photo.class.getClassLoader()));
    }

    public Product() {
    }

    public String getCassetteImage() {
        if (!TextUtils.isEmpty(cassetteImage)) {
            return NetworkManager.getInstance().getBaseUrl() + cassetteImage;
        } else {
            return cassetteImage;
        }
    }

    public void setCassetteImage(String cassetteImage) {
        this.cassetteImage = cassetteImage;
    }

    public String getExhibitionImage() {
        if (!TextUtils.isEmpty(exhibitionImage)) {
            return NetworkManager.getInstance().getBaseUrl() + exhibitionImage;
        } else {
            return exhibitionImage;
        }
    }

    public void setExhibitionImage(String exhibitionImage) {
        this.exhibitionImage = exhibitionImage;
    }

    public String getEditedAt() {
        return editedAt;
    }

    public void setEditedAt(String editedAt) {
        this.editedAt = editedAt;
    }

    public String getReviewedAt() {
        return reviewedAt;
    }

    public void setReviewedAt(String reviewedAt) {
        this.reviewedAt = reviewedAt;
    }

    public Object getPreviousProduct() {
        return previousProduct;
    }

    public void setPreviousProduct(Object previousProduct) {
        this.previousProduct = previousProduct;
    }

    public List<Object> getDiff() {
        return diff;
    }

    public void setDiff(List<Object> diff) {
        this.diff = diff;
    }

    public List<Object> getParameterDiff() {
        return parameterDiff;
    }

    public void setParameterDiff(List<Object> parameterDiff) {
        this.parameterDiff = parameterDiff;
    }

    public List<Object> getPhotosDiff() {
        return photosDiff;
    }

    public void setPhotosDiff(List<Object> photosDiff) {
        this.photosDiff = photosDiff;
    }

    public List<Photo> getPhotos() {
        return photos;
    }

    public void setPhotos(List<Photo> photos) {
        this.photos = photos;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPNO() {
        return pNO;
    }

    public void setPNO(String pNO) {
        this.pNO = pNO;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public Object getNewCategoryId() {
        return newCategoryId;
    }

    public void setNewCategoryId(Object newCategoryId) {
        this.newCategoryId = newCategoryId;
    }

    public int getOperatorId() {
        return operatorId;
    }

    public void setOperatorId(int operatorId) {
        this.operatorId = operatorId;
    }

    public String getReviewStatus() {
        return reviewStatus;
    }

    public void setReviewStatus(String reviewStatus) {
        this.reviewStatus = reviewStatus;
    }

    public Object getRejectReason() {
        return rejectReason;
    }

    public void setRejectReason(Object rejectReason) {
        this.rejectReason = rejectReason;
    }

    public boolean isUploadingImage() {
        return uploadingImage;
    }

    public void setUploadingImage(boolean uploadingImage) {
        this.uploadingImage = uploadingImage;
    }

    public boolean isUploadFailed() {
        return uploadFailed;
    }

    public void setUploadFailed(boolean uploadFailed) {
        this.uploadFailed = uploadFailed;
    }

    public String getImageId() {
        return imageId;
    }

    public void setImageId(String imageId) {
        this.imageId = imageId;
    }

    public Object getCad() {
        return cad;
    }

    public void setCad(Object cad) {
        this.cad = cad;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    public List<Shelf> getShelves() {
        return shelves;
    }

    public void setShelves(List<Shelf> shelves) {
        this.shelves = shelves;
    }

    public List<Storage> getStorages() {
        return storage;
    }

    public void setStorages(List<Storage> storages) {
        this.storage = storages;
    }

    public Operator getOperator() {
        return operator;
    }

    public void setOperator(Operator operator) {
        this.operator = operator;
    }

    public List<Parameter> getParameters() {
        return parameters;
    }

    public void setParameters(List<Parameter> parameters) {
        this.parameters = parameters;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(cassetteImage);
        dest.writeValue(exhibitionImage);
        dest.writeValue(editedAt);
        dest.writeValue(reviewedAt);
        dest.writeValue(previousProduct);
        dest.writeList(diff);
        dest.writeList(parameterDiff);
        dest.writeList(photosDiff);
        dest.writeValue(id);
        dest.writeValue(pNO);
        dest.writeValue(categoryId);
        dest.writeValue(newCategoryId);
        dest.writeValue(operatorId);
        dest.writeValue(reviewStatus);
        dest.writeValue(rejectReason);
        dest.writeValue(uploadingImage);
        dest.writeValue(uploadFailed);
        dest.writeValue(imageId);
        dest.writeValue(cad);
        dest.writeValue(createdAt);
        dest.writeValue(updatedAt);
        dest.writeList(shelves);
        dest.writeValue(operator);
        dest.writeList(parameters);
        dest.writeList(photos);
    }

    public int describeContents() {
        return 0;
    }

    @Override
    public int getItemType() {
        return ProductSummaryManager.getInstance().getCurrentState();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Product product = (Product) o;

        if (id != product.id) return false;
        return pNO != null ? pNO.equals(product.pNO) : product.pNO == null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (pNO != null ? pNO.hashCode() : 0);
        return result;
    }
}
